<template>
	<view class="main_bg">
		<app-header title="维修列表"></app-header>
		<view class="tabs flex-s">
			<view class="tabs_son flex-c" :class="[query.member_status==''?'active':'']" @click="setActive('')">全部
			</view>
			<!-- 		<view class="tabs_son flex-c" :class="[query.member_status=='0'?'active':'']" @click="setActive('0')">待处理
			</view> -->
			<view class="tabs_son flex-c" :class="[query.member_status=='1'?'active':'']" @click="setActive('1')">已派单
			</view>
			<view class="tabs_son flex-c" :class="[query.member_status=='2'?'active':'']" @click="setActive('2')">已处理
			</view>
			<view class="tabs_son flex-c" :class="[query.member_status=='3'?'active':'']" @click="setActive('3')">已完成
			</view>
		</view>
		<scroll-view scroll-y="true" :refresher-triggered="triggered" class="scroll-y" @refresherrefresh="handleRefresh"
			@scrolltolower="lower" :style="{height:scrollHeight}" :enhanced="true" :show-scrollbar="true">
			<view class="device_list">
				<view class="list" v-for="(item,index) in list" :key="index">
					<view @click="$func.toUrl('/pages_worker/repair/detail?id='+item.id)">
						<view class="cell">
							<view class="label flex-c">
								<view class="tag flex-c" :class="'status_'+item.member_status">
									{{item.member_status_name}}
								</view>
								报修编号：
							</view>
							<view class="value">{{item.device_sns}}</view>
						</view>
						<view class="cell">
							<view class="label">客户名称：</view>
							<view class="value">{{item.shop_name}}</view>
						</view>
						<view class="cell">
							<view class="label">客户地址：</view>
							<view class="value">{{item.store_address}}</view>
						</view>
						<view v-if='item.device_id>0'>
							<view class="cell">
								<view class="label">设备分类：</view>
								<view class="value">{{item.type_name1}}</view>
							</view>
							<view class="cell">
								<view class="label">设备类型：</view>
								<view class="value">{{item.type_name2}}</view>
							</view>
							<view class="cell">
								<view class="label">设备品牌：</view>
								<view class="value">{{item.type_name3}}</view>
							</view>
							<!-- <view class="cell">
								<view class="label">设备系列：</view>
								<view class="value">{{item.type_name4}}</view>
							</view> -->
							<view class="cell">
								<view class="label">设备名称：</view>
								<view class="value">{{item.device_name_f}}</view>
							</view>
							<view class="cell">
								<view class="label">设备编号：</view>
								<view class="value">{{item.device_sn_f}}</view>
							</view>

						</view>
						<view v-else>
							<view class="cell">
								<view class="label">设备名称：</view>
								<view class="value">{{item.device_name_f || item.device_name}}</view>
							</view>
							<view class="cell">
								<view class="label">设备规格：</view>
								<view class="value">{{item.device_spec}}</view>
							</view>
							<view class="cell">
								<view class="label">故障描述：</view>
								<view class="value">{{item.describe}}</view>
							</view>
						</view>
					</view>
					<view class="flex-c" style="justify-content: flex-end;"
						v-if="item.member_status==1&&item.can_handle ==1">

						<view class="btn flex-c" @click="$func.toUrl('/pages_worker/repair/detail?id='+item.id)">去维修
						</view>

					</view>

				</view>
			</view>
			<u-divider text="暂无数据" v-if="list.length==0 && finish"></u-divider>
			<u-divider text="暂无更多数据" v-if="list.length>0 && finish"></u-divider>
			<u-divider text="加载中" v-if="loading"></u-divider>
		</scroll-view>
	</view>
</template>

<script>
	const systemInfo = uni.getSystemInfoSync();
	const safeArea = systemInfo.safeArea;
	export default {
		data() {
			return {
				status: ['已报修待指派', '已指派', '维修已处理', '已完成'],
				loading: false,
				triggered: false,
				finish: false,
				total: 0,
				list: [],
				query: {
					member_status: '',
					page: 1,
					pageSize: 20
				},
			}
		},
		computed: {
			scrollHeight() {
				return 'calc(100vh - 100rpx)'
			},
		},
		onLoad(options) {
			if (options.device_id) {
				this.$set(this.query, 'device_id', options.device_id)
			}
			// if (options.from_type) {
			// 	this.$set(this.query, 'from_type', options.from_type)
			// }

		},
		onShow() {
			this.list = []
			this.$set(this.query, 'page', 1)
			this.getList()
		},
		methods: {
			setActive(active) {
				this.$set(this.query, 'member_status', active)
				this.list = []
				this.query.page = 1
				this.finish = false
				this.getList()
			},
			handleRefresh(e) {
				this.triggered = true;
				setTimeout(() => {
					this.query.page = 1
					this.list = []
					this.getList()
				}, 500)
			},
			lower() {
				if (this.list.length < this.total) {
					this.query.page = this.query.page + 1
					this.getList()
				} else {
					this.finish = true
					this.loading = false
				}
			},
			getList() {
				this.loading = true
				this.$http.post('/data/api.auth.User/companyMaintenancelists', {
					...this.query
				}).then(res => {
					this.list = [...this.list, ...res.data.list]
					this.total = res.data.page.total || 0
					this.loading = false
					this.triggered = false;
					this.finish = true
				}).catch(() => {
					this.loading = false
				})
			},
			setStatus(row) {
				uni.showModal({
					title: '提示',
					content: '确定结束吗？',
					confirmText: "确定",
					cancelText: "取消",
					success: (res) => {
						if (res.confirm) {
							this.$http.post('/data/api.auth.User/maintenanceHandle', {
								id: row.id,
							}).then(res => {
								row.member_status_name = "已完成"
								row.member_status = 2
							})
						} else if (res.cancel) {

						}
					}
				});

			}

		}
	}
</script>

<style scoped lang="scss">
	.tabs {
		height: 100rpx;
		background: #FFFFFF;

		.tabs_son {
			font-size: 28rpx;
			color: #ADADAD;
			flex: 1;
			height: 100rpx;
			border-bottom: 2rpx solid #FFFFFF;
			position: relative;


			&.active {
				color: #4F6FF6;

				&::after {
					position: absolute;
					content: '';
					background-color: #4F6FF6;
					width: 80rpx;
					height: 4rpx;
					bottom: 0;
				}

				// border-bottom: 2rpx solid #4F6FF6;
			}
		}
	}

	.device_list {
		// margin-top: 20rpx;
		padding: 20rpx 0;

		background: rgba(255, 255, 255, 1);

		.list {
			border-radius: 20rpx;
			margin: 0 20rpx 20rpx 20rpx;
			padding: 20rpx;

			border: 1px solid #EBEBEB;

			.btn {
				width: 158rpx;
				height: 80rpx;
				background-color: #4F6FF6;

				border-radius: 10rpx;
				font-size: 30rpx;

				color: #FFFFFF;
				margin-left: 10rpx;
			}


		}
	}

	.cell {
		min-height: 60rpx;

		.label {
			color: #333333;

			.tag {
				min-width: 92rpx;
				padding: 0 5rpx;
				height: 38rpx;
				background-color: #D81E06;
				opacity: 1;
				border-radius: 4rpx;
				font-size: 22rpx;
				color: #FFFFFF;
				margin-right: 10rpx;

				&.status_1 {
					background-color: #4F6FF6;
				}

				&.status_2 {
					background-color: #AAAAAA;
				}

				&.status_3 {
					background-color: #67C23A;
				}
			}
		}

		.value {
			// flex: 1;
			// justify-content: flex-start;
			color: #ADADAD;
		}
	}
</style>